<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<form action="" method="post">
			<table border="1" cellspacing="0" cellpadding="10px" id="actorTable";">
				<tr>
					<th></th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>家庭住址</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>曾小贤</td>
					<td>男</td>
					<td>40</td>
					<td>爱情公寓3602</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>胡一菲</td>
					<td>女</td>
					<td>39</td>
					<td>爱情公寓3602</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>吕子乔</td>
					<td>男</td>
					<td>35</td>
					<td>爱情公寓3601</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>陈美嘉</td>
					<td>女</td>
					<td>30</td>
					<td>爱情公寓3601</td>
				</tr>
			</table>
			<input type="checkbox" name="" id="checkAllId" value="" onclick="doselAll()" />全选<br />
			<input type="checkbox" name="" id="allCheckByWoman" value="" onclick="doActionSex()"/>全选女<br />
			        <input type="checkbox" name="" id = "allCheckByMan" value="" onclick="doActionMan()"/>全选男<br />
		</form>
	</body>
	<script type="text/javascript">
		function doselAll(){
			var actorTableObj = document.getElementsById('actorTable');
			var inputAll = stuTableObj.getElementsByTagName('input');
			console.log(inputAll);
			var checkAllValue = document.getElementById('checkAllId').checked;s
			console.log(checkAllValue)
			for(var i=0;i<inputAll.length;i++){
				inputAll[i].checked = checkAllValue;
			}
			
		}
		 function doActionMan(){
		            var stuInfo = document.getElementById('actorTable');
		            var checkboxAll = stuInfo.getElementsByTagName('input');
		            var sex = stuInfo.getElementsByClassName('sex');
		            var checkById = document.getElementById('allCheckByMan').checked;
		            console.log(checkById);
		            for(var i = 0 ; i<sex.length ; i++){
		                if(sex[i].innerText == '男'){
		                    checkboxAll[i].checked = checkById;
		                    console.log(sex[i].innerText);
		                    }
		                }
		            }
		        
		        function doActionSex(){
		            var stuInfo = document.getElementById('actorTable');
		            var checkboxAll = stuInfo.getElementsByTagName('input');
		            var sex = stuInfo.getElementsByClassName('sex');
		            var checkById = document.getElementById('allCheckByWoman').checked;
		            console.log(checkById);
		            
		            for(var i = 0 ; i<sex.length ; i++){
		                if(sex[i].innerText == '女'){
		                    checkboxAll[i].checked = checkById;
		                    console.log(sex[i].innerText);
		                    }
		                }
		            }
	</script>
	
</html>
